﻿package 
{
	import flash.display.*;
	import flash.events.*;
	import flash.net.URLRequest;

	public class PreLoader extends MovieClip
	{
		// Loader to load up the website .swf
		public var loader:Loader;

		public var websiteMain:MovieClip;

		public function PreLoader()
		{
			// ADDED_TO_STAGE event handler
			addEventListener(Event.ADDED_TO_STAGE, addedToStageHandler);
		}
		
		public function addedToStageHandler(e:Event):void
		{
			// Initialize a new Loader
			loader = new Loader();

			// Add event handlers
			loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteLoadedWebsite);
			loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressLoadingWebsite);

			// URLRequest to specify the filename to load;
			var urlRequest:URLRequest = new URLRequest("website.swf");

			// Load the URLRequest
			loader.load(urlRequest);

			// Remove the ADDED_TO_STAGE event handler
			removeEventListener(Event.ADDED_TO_STAGE, addedToStageHandler);
		}
		
		public function onProgressLoadingWebsite(e:ProgressEvent):void
		{
			var percent:Number = e.bytesLoaded / e.bytesTotal;
			percent = percent * 100;
			prog_bar.x = prog_bar.x + percent / 3;
			// trace(int(percent));
		}
		
		public function onCompleteLoadedWebsite(e:Event):void
		{
			// Add the website to the stage
			addChild(loader);

			// Get a reference to it
			websiteMain = loader.content as MovieClip;
		}
	}
}